/**
 * 
 */
package com.humanmonth.rea.pic;

import java.util.List;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;

import com.humanmonth.framework.dao.JDOTemplate;

/**
 * @author 林子龙
 * 
 */
public class PictureService {
	@SuppressWarnings("unused")
	private final Logger log=Logger.getLogger(this.getClass().getName());
	/**
	 * 保存图片
	 */
	public void savePic(final Picture pic) {
		new JDOTemplate<Picture>() {
			@Override
			public void deal(PersistenceManager pm, List<Picture> result) {
				pm.makePersistent(pic);
				pm.flush();
			}
		}.execute();
	}

	/**
	 * 以ID和条件获取图片
	 */
	public Picture queryPicById(final Long id) {
		return new JDOTemplate<Picture>() {
			@Override
			public void deal(PersistenceManager pm, List<Picture> result) {
				result.add((Picture) pm.getObjectById(Picture.class,id));
			}
		}.execute().get(0);
	}

	/**
	 * 查找所有的图片
	 */
	public List<Picture> queryAllPicture() {
		return new JDOTemplate<Picture>() {
			@SuppressWarnings("unchecked")
			@Override
			public void deal(PersistenceManager pm, List<Picture> result) {
				Object obj = pm.newQuery("select from " + Picture.class.getName()).execute();
				result.addAll((List<Picture>) obj);
			}
		}.execute();
	}
}
